Adding a bit more error handling. Test phase, not sure if it's actually working