Working balance function; more tests and fixup required