moved all pre-checking stuff to the bottom