fix onerror bugs. cleaned up main. preparing to start on server