Edited code for good functionality