exam solution, needs some bug fixes