added header, improved code