Cleaned up the insert function