debugged script for errors