Remove duplicate substr.
Small cleanup.
Fix condition and some small cleanup.
Cleanups.