Cleaned things up and fixed some minor bugs