ported everything but main.cpp