Fixes for creating lines and instruments, general refactoring