add explicit type conversion
various bug fixes