Overhaul to fix remained bugs
Merge pull request #2 from sonots/rewrite

Overhaul to fix remained bugs