Rearranged code
Added main function to file