optimizing a lot, make the code more intuitive