Fix for issue #5629

My first pull request, so I hope I did everything correctly :smiley: 

- Reverted #5013
- Created new method to set custom status codes
- Fixed "Notice: Undefined offset" (#5629)