Rewrote most of the script. Added 'update' functionality.