Library: Fix undefined variables and cleanup unused ones