Finalized script. ( I hope, have to finish testing)