Fixing the code to suit Kaelig's demands