Overhaul to improve readability and flexibility