Library refactored and example fixed