fixed a bug and added a new function