Further refactored working code.