Main function and fixes

Main function's been added. Code fixes have been made.