Refactor for readbility and speed