Unit tests and script cleanup