Simplify & beautify the code by using `nan`