Bug fixes and some improves