Bug fixes and potential further improvements