Miscellaneous bug fixes

Hello Seist. I am not sure if  these changes are warranted because I remember a reversion taking place to restore Skylight to a stable state. I'm not sure if these changes would break Skylight once again. Let me know if there are any problems.