#25: Better logic and cleanup