Added logging where necessary