code cleanup, more tests and examples