#49 Restructure functions and migration