Added some bug fixes and fixed 3 code smells