Cleaning up unused functions and rewriting existing to look better