[WIP] Big code cleanup