Fixed bug caused after cleaning up code