Some improvemetns and fix bugs