Move expansion code to correct location