Remove redundant functions, improve existing, fix formatting