Minor bug fixes and refacotring