refactor all code, yes it's dirty