Started massive rewrite and refactoring