Improving the code after 1 year of abandonment. Trying to pick it put again...