improvements in alghoritm and layout