Cleaned up by making methods for duplicate code