complete solution, added reflection and driver code