Update main file to remove config
Added more comments and fixed some formatting
updated and improved logic