cleaned up the class a bit and fixed a bug