Code Rewrite for performance

Signed-off-by: Rajat Kosh <rajatkosh@outlook.com>