taking into account foreign keys; split source code in several files; (NOT FULLY WORKING YET)