Many small bug fixes and minor changes

Signed-off-by: Ravn T-M <ravn.tm@gmail.com>