Refactored some of the transparency code into a separate function - more refactoring needed