working code, ready for submission