efficiency fixes and bug fixes