fix for #227

@settinghead please review
@olegrise can this be put into the service layer? Because 

1. this could potentially be reused somewhere else 
2. I was worried the controller logic gets too bloated