re-structuring / cleaning up logic