add documentation
use typeof instead of instanceof, cleanup