Changed std::pair to struct, and some bugfixes