Bug fixes and general improvements

Signed-off-by: Marcin Wiatr <marcin@qi-interactive.com>