Migrating to a better code - still have problems