Some decently cleaned code