Code refactor. WIP.