Refactors code

Just some quick refactor to prevent failure when the defined attrs are wrong