Fixing some None reference issues, changing modules to detect if they are being run or imported.

Signed-off-by: Dsyko <dsykora@gmail.com>