fixed a bug and added some utility functions