Fixed helper functions, code cleanup