fixed several bugs found by udacity submission