Cleanup and make more generic