Fixed warning, cleaned up code, added comments