added exception handling (but still broken)