Clean up unused variables
Fix blockwise end detection