Fixed to be pass by reference (fixing some bugs) and added in some initial support for choosing layer options