Fixed all easy compiler errors, and added some helper functions