Adapted code to buffer signal and worked on functions