Bug fix and cleanup

- When factories are generated, they are now saved to the DB
- Found that I needed a timeout around the jstree generation after a
socket.io tree update.  Looks like jQuery is trying to access variables
before they are deleted, then it gets confused.
- Added comments and cleaned up some code.