Cleaned up duplicate code