Move add and remove layer into functions