Prototype: Refactored into multiple files, More checks and states