some error checking added into g and a option