Refactored code and did some cleanup
Modified create function code to make the function more generic