Improved core.cpp

Now it uses friend ids whenever it's possible.