Moving data logic into model function.
Added Error Handling