Added new functions and fixed bugs