added some error checking to binding code