Removed duplicated logic. Added minor fixes.