Some bugfixes and cleanup. Added client