Updated

global//mains appropriated
cleaned code
minimized unnecessary vars