revamped all code