comments added, some refcatoring ...