More bug fixes and improvement