Cleaning up typos and add more error checking