Reshuffled code, split some large files for readbility.