Found great script by Tomas Nevar - modified slightly for single-script functionality