Changing class structure, minor fixes and tests