Cleaned up, removed duplicate code