added 3 functions, fixed a bug