Some bug fixes and improvements.

Signed-off-by: Thanashyam Raj <thanashyam@gmail.com>