fixed threading error and removed hlint warnings