Applying Layers Better

Layers are now applied correctly. Multiple definitions/citations in the same body of text are now highlighted correctly. 

Also, I fixed the parameter checking logic in static_html_generator.py