Cleaned up functions in inserted and main