work in progress
work in progress (added error logging)