updated logic

crud and search function should work now.
Apologise if there is any bug, because I only do a manual test so far.
Some of parts many need to change as I may misunderstood some setting.