reorganized code to separate Model, View, Update, Input