working first draft, fixed undefined error