Code fixes

Various code fixes, mostly discovered by MSVC code static analyzer .
@anssih remaped is of type bool. what was your original intent?