Cleaned up debugging messages and made some minor code improvements