made some small changes and thanks to Alf Høgemark's advice