WIP: refactored the mess