MAIN CODE!!!

This is working ok atm, needs refinement though