Added a new script and some bug fixes