More bug fixes and tests. Added efficiency tests