Big refactor of basic to clean it up and make the program logic easier to follow

Change-Id: I32e911c9142373484c6295ef5905bd2cb548ade3