Version 3.0, refactored, tests added, bugs fixed