refactor all the code

it will still crash for now