fix tabs & white space and improved logic