Separated the data preparation from the main code. Also ported the format to a .Rdata file