Updated with the re-factor for performance