Replaced print stack trace with appropriate error logging