some unit testing and bug fixing