fixing potential issues
and cleanup