first ugly implementation (one long method)
splitting up the long method into smaller methods.