Fixed some bugs, and added new functionalities