Moved core functions to flat-2d lib