Final cleaned-up code