added javascript library loading, some cleanup in exception handling