fixed compilation problems
made code compilable and cleaned it up a little bit