some reorganization, added a test