General improvements and bugs fixes