Changed code layout
Minor performance improvements