First attempt to simplify the library.

Library is now more 'statemachine' like. Untested though..