Fixed bugs discovered while testing