fixing broken optimization

… broke due to shuffling some code around.