fixed script and add unit tests