first solution to challenge 004, ugly but it works