renaming and rearranging stuff for clarity and better modularity

Signed-off-by: Mikolaj Szabo <savingprivateblue@gmail.com>