Small Fixes, refactoring, fixed crash