Massive refactor + add functionality