Final version with gui improvements