more refactoring work - need to prepare web side to test it.