problem 32, quick and dirty version, needs to be cleaned up