An attempt at saner code