refactored caching, fixed margin
added scaling