Refactering user database code