moved some sections around for readability and added a couple of new bits with if/else code