Fixed bugs discovered through unit testing