Improved and pretty much completed script