revamped to make everything more stable