Cleanup code for #543 fix