Better and more logical implementation of previous commit