Heavily modified
clean code