fix compiler warning and simplify some excess code