Began error handling, changed some psudocode