integrated Piotr Fusik's suggestions