Added motivation text, cleaned up code