Revamped/Rewrite. Change to single file implementation