Almost all programm logic done