move code into proper layers