alot of changes (thanks to PhilZ)