More bug fixes and improvments