Fixed imports, added comment
Give more access
Safer code for MOAPI support

-Removed repetitive part
-Added logging
-Checked user input