added some error checking
removed debug