Reimplemented everything. Seems faster and cleaner now.