Bug fixes and enhancements

Signed-off-by: Johan Bregell <johan@bregell.se>