Refactored; made variable scope flow (recalc is still broken, though)