improved problem4 correctness, finished beta version of problem5