Add unit tests

Add unit tests and small changes in the script.