added unit testing, fixed a bug