Segmented the code and started to implement messagehandling.