Added class template, moved some stuff, fixed a bug.