Logging and fixes for index out of range exception