Consolidate some functions, remove dead code