refactor data layer; fix random number generator bug.