Cleaned the code.

now with RAII and some initializer lists.