Refined, refactorred, and added/improved a few features.