Completely rewrote. Still a work in progress but should not be as buggy.