Rewrite

Complete rewrite for a more legible read + license