Working code .. room for improvement but good enough to submit