fixed some bugs and made module more generic