I spent several days on building a system about this. And make it work well with serveral thousand lines of codes.