divided to multiple files. Improved algorithm