fixed a minor bug. script works as specified now