Code cleanup, using better indentation and also replacing various continue statements with if then else statements