Added error checks and loading mask