Fix a minor logic flaw and an useless conversion between datatypes. Thanks to @Laniax for the datatype part of this commit.