Cleaned up data-reading and sampling for greater speed