Adding some functionallity and fix some bugs