top down fully working code.