fixed some errors, made more dynamic