Made some changes, made code a bit more optimized