Refactory and fixes

DO NOT MERGE YET